package com.codegen.gbcodegen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codegen.gbcodegen.service.SysGeneratorService;
import com.codegen.gbcodegen.util.R;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@AllArgsConstructor
public class IndexController {

    private final SysGeneratorService sysGeneratorService;


    @GetMapping("/index")
    public String index(ModelMap map ) {

        return "index";
    }

    @RequestMapping("/codes")
    public String code(ModelMap map ) {

        return "code";
    }

    @GetMapping("/code")
    @ResponseBody
    public Map getPage(Page page, String tableName) {
        IPage r =  sysGeneratorService.getPage(page, tableName);
        Map map = new HashMap<>();
        map.put("code","");
        map.put("msg","");
        map.put("count",r.getTotal());
        map.put("data",r.getRecords());
        return map;
    }


    @GetMapping("/yyy")
    public String sss(ModelMap map ) {

        return "code";
    }

}

